//
//  HttpServerCfg.cpp
//  http_server
//
//  Created by Zirpon Cheung on 15-3-26.
//  Copyright (c) 2015年 Zirpon Cheung. All rights reserved.
//

#include "HttpServerCfg.h"

#define DEFAULT_CFG_HOME_DIR    "/Users/champon/ShareFiles"
#define DEFAULT_CFG_PORT        "3356"
#define DEFAULT_CFG_BACK        "5"

struct HttpServerCfgDef HttpServerCfg::cfg;

void HttpServerCfg::load(string path)
{
    File cfgFile(path);
    
    cfg.homeDir = cfgFile.getString("home_dir", DEFAULT_CFG_HOME_DIR);
    
    string cfg_ip= cfgFile.getString("ip", "");
    if (cfg_ip.empty()) {
        char ipResult[1024];
        memset(ipResult, '\0', sizeof(ipResult));
        Socket::getLocalhost("en0", ipResult);
        cfg_ip = ipResult;
    }
    
    cfg.ip  = cfg_ip;

    string port = cfgFile.getString("port", DEFAULT_CFG_PORT);
    cfg.port    = atoi(port.c_str());
    
    string back = cfgFile.getString("back", DEFAULT_CFG_BACK);
    cfg.back    = atoi(back.c_str());

}

struct HttpServerCfgDef HttpServerCfg::getHttpServerCfgDef()
{
    return cfg;
}






























